package com.lmqb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lmqb.bean.SysUser;
import com.lmqb.entry.MenuTitle;
import com.lmqb.page.EmailLogPager;
import com.lmqb.page.SmsLogPager;
import com.lmqb.page.WeiXinLogPager;
import com.lmqb.service.JiaoYanService;
import com.lmqb.service.LogService;
import com.lmqb.util.StrUtil;

@Controller
public class LogController extends BaseController{

	@Autowired
	private JiaoYanService jiaoYanService;
	
	@Autowired
	private LogService logService;
	
	//跳转到邮件发送日志页面
	@RequestMapping(value="emailLog.html")
	public String toEmailLog(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,EmailLogPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(EmailLogPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			EmailLogPager emailPager=logService.selectEmailPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, emailPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("日志管理");
			menuTitle.setMenu("邮件发送");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "emailLogList";
	}
	
	//跳转到短信发送日志页面
	@RequestMapping(value="smsLog.html")
	public String toSmsLog(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,SmsLogPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(SmsLogPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			SmsLogPager smsPager=logService.selectSmsPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, smsPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("日志管理");
			menuTitle.setMenu("短信发送");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "smsLogList";
	}
	
	//跳转到微信发送日志页面
	@RequestMapping(value="weixinLog.html")
	public String toWeixinLog(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,WeiXinLogPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(WeiXinLogPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			WeiXinLogPager weiXinPager=logService.selectWeiXinPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, weiXinPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("日志管理");
			menuTitle.setMenu("微信发送");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "weiXinLogList";
	}
}
